package com.titaniume.rqbbitmq.two;

import com.rabbitmq.client.Channel;
import com.titaniume.rqbbitmq.util.RabbitMqUtils;

import java.util.Scanner;

/**
 * @ProjectName: rqbbitmq-hello
 * @Package: com.titaniume.rqbbitmq.two
 * @ClassName: Task01
 * @Author: huangrenfei
 * @Description: 消息生产者
 * @Date: 2021/12/17 14:54
 * @Version: 1.0
 */
public class Task01 {


    //队列名称
    public static final String QUEUE_NAME = "test";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //声明队列
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);
        //控制台输入消息
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String message = scanner.nextLine();
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            System.out.println("发送消息完成:" + message);
        }
    }
}
